<?php
require_once 'PHPUnit/Framework.php';

require_once(dirname(__FILE__).'/../../../models/user/UCModUserStatistics.php');
/**
@assert (...) == X    assertEquals(X, method(...))
@assert (...) != X    assertNotEquals(X, method(...))
@assert (...) === X    assertSame(X, method(...))
@assert (...) !== X    assertNotSame(X, method(...))
@assert (...) > X    assertGreaterThan(X, method(...))
@assert (...) >= X    assertGreaterThanOrEqual(X, method(...))
@assert (...) < X    assertLessThan(X, method(...))
@assert (...) <= X    assertLessThanOrEqual(X, method(...))
@assert (...) throws X    @expectedException X
*/
class UCModUserStatisticsTest extends PHPUnit_Framework_TestCase {
    
    protected function setUp()
    {
    }
    
    protected function tearDown()
    {
         //$this->_stat->setValue(1234);
    }
    
    function test_getValue()
    {
        $stat = UCModUserStatistics::getStat(1212175243);
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$this->assertTrue($stat->getValue($index) !== false);
			$index += 1;
		}
    }
	
    function test_getValues()
    {
        $stat = UCModUserStatistics::getStat(1212175243);
		$index = _UC_STAT_STATRT;
		$keys = array();
		while ($index <= _UC_STAT_END) {
			$keys []= $index;
			$index += 1;
		}
		$values = $stat->getValues($keys);
		foreach ($keys as $key) {
			$this->assertTrue(isset($values[$key]));
		}
    }

    function test_setValue()
    {
        $stat1 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		$temp = array();
		while ($index <= _UC_STAT_END) {
			$value = $stat1->getValue($index);
			$this->assertTrue($value !== false);
			$temp[$index] = $value;
			$stat1->setValue($index, $index);
			$index += 1;
		}

		// read again
        $stat2 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$value = $stat2->getValue($index);
			$this->assertTrue($value !== false);
			$this->assertTrue($value === $index);
			$index += 1;
		}

		// reset data
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$ret = $stat2->setValue($index, $temp[$index]);
			$this->assertTrue($ret !== false);
			$index += 1;
		}

		// read again
        $stat3 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$value = $stat3->getValue($index);
			$this->assertTrue($value !== false);
			$this->assertTrue($value === $temp[$index]);
			$index += 1;
		}
    }

    function test_setValues()
    {
        $stat1 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		$temp = array();
		$newVals = array();
		while ($index <= _UC_STAT_END) {
			$value = $stat1->getValue($index);
			$this->assertTrue($value !== false);
			$temp[$index] = $value;
			$newVals[$index] = $index;
			$index += 1;
		}

		$stat1->setValues($newVals);

		// read again
        $stat2 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$value = $stat2->getValue($index);
			$this->assertTrue($value !== false);
			$this->assertTrue($value === $newVals[$index]);
			$index += 1;
		}

		// reset data
		$stat2->setValues($temp);
		// read again
        $stat3 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$value = $stat3->getValue($index);
			$this->assertTrue($value !== false);
			$this->assertTrue($value === $temp[$index]);
			$index += 1;
		}
    }

    function test_increaseValue()
    {
        $stat1 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		$temp = array();
		while ($index <= _UC_STAT_END) {
			$value = $stat1->getValue($index);
			$this->assertTrue($value !== false);
			$stat1->increaseValue($index, $index);
			$temp[$index] = $value + $index;
			$index += 1;
		}

		// read again
        $stat2 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$value = $stat2->getValue($index);
			$this->assertTrue($value !== false);
			$this->assertTrue($value === $temp[$index]);
			$index += 1;
		}

		// increase data
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$ret = $stat2->increaseValue($index, -$index);
			$this->assertTrue($ret !== false);
			$index += 1;
		}

		// read again
        $stat3 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$value = $stat3->getValue($index);
			$this->assertTrue($value !== false);
			$this->assertTrue($value === $temp[$index] - $index);
			$index += 1;
		}
    }
	
	function test_increaseValues()
    {
        $stat1 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		$temp = array();
		$newVals = array();
		while ($index <= _UC_STAT_END) {
			$value = $stat1->getValue($index);
			$this->assertTrue($value !== false);
			$temp[$index] = $value;
			$newVals[$index] = $index;
			$index += 1;
		}

		$stat1->increaseValues($newVals);

		// read again
        $stat2 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$value = $stat2->getValue($index);
			$this->assertTrue($value !== false);
			$this->assertTrue($value === $temp[$index] + $newVals[$index]);
			$index += 1;
		}

		// reset
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$newVals[$index] = -$newVals[$index];
			$index += 1;
		}
		$stat2->increaseValues($newVals);

		// read again
        $stat3 = new UCModUserStatistics(1212175243);
		$index = _UC_STAT_STATRT;
		while ($index <= _UC_STAT_END) {
			$value = $stat3->getValue($index);
			$this->assertTrue($value !== false);
			$this->assertTrue($value === $temp[$index]);
			$index += 1;
		}
    }
    
}


?>